<script>
sequenceOnload.push(fillDialogCalendar);

function fillDialogCalendar(){
	$(".datepicker").datepicker({
		changeMonth: true,
		changeYear: true,
		monthNamesShort: ShortMonth,
		monthNames: ShortMonth,
		dayNamesShort: ShortDay,
		dayNames: ShortDay,
		dateFormat: SharedData.General.dateFormat.dateTimeFormat,
		onSelect: function(dateText) {
			$('.pageheader').get(0).change.val($(".datepicker").val());
			$('.pageheader').get(0).change.text($(".datepicker").val());
			$('.pageheader').get(0).changed = true;
			close_table($(".datepicker").val());
		}
	});
}
function on_focus(dom){dom.css("color","#9999FF");dom.css("cursor","pointer");}
function on_blur(dom){dom.css("color","#330099");dom.css("cursor","pointer");}
function fillQuickDate(){
	var min = $(".datepicker").datepicker("option", "minDate");
	var max = $(".datepicker").datepicker("option", "maxDate");
	
	var now = getDate();
	var d = '';
	var added = 0; if(now>=min) if(max==null || now<=max) d+='<span class="quickDateItem" value="'+now+'" onclick="quickdate(new Date($(this).attr(\'value\')));" >' + ShortDay[now.getDay()] + ' ' + now.getFormatedString() + '&nbsp;<'+Calendar_Today+'> </span><br>';
	added = 1; if(now.addDate(added)>=min) if(max==null || now.addDate(added)<=max) d+='<span class="quickDateItem" value="'+now.addDate(added)+'" onclick="quickdate(new Date($(this).attr(\'value\')));" >' + ShortDay[now.addDate(added).getDay()] + ' ' + now.addDate(added).getFormatedString() + '&nbsp;<'+Calendar_Tomorrow+'> </span><br>';
	added = 2; if(now.addDate(added)>=min) if(max==null || now.addDate(added)<=max) d+='<span class="quickDateItem" value="'+now.addDate(added)+'" onclick="quickdate(new Date($(this).attr(\'value\')));" >' + ShortDay[now.addDate(added).getDay()] + ' ' + now.addDate(added).getFormatedString() + ' </span><br>';
	added = 3; if(now.addDate(added)>=min) if(max==null || now.addDate(added)<=max) d+='<span class="quickDateItem" value="'+now.addDate(added)+'" onclick="quickdate(new Date($(this).attr(\'value\')));" >' + ShortDay[now.addDate(added).getDay()] + ' ' + now.addDate(added).getFormatedString() + ' </span><br>';
	added = 4; if(now.addDate(added)>=min) if(max==null || now.addDate(added)<=max) d+='<span class="quickDateItem" value="'+now.addDate(added)+'" onclick="quickdate(new Date($(this).attr(\'value\')));" >' + ShortDay[now.addDate(added).getDay()] + ' ' + now.addDate(added).getFormatedString() + ' </span><br>';
	added = 7; if(now.addDate(added)>=min) if(max==null || now.addDate(added)<=max) d+='<span class="quickDateItem" value="'+now.addDate(added)+'" onclick="quickdate(new Date($(this).attr(\'value\')));" >' + ShortDay[now.addDate(added).getDay()] + ' ' + now.addDate(added).getFormatedString() + ' </span><br>';
	added = 14; if(now.addDate(added)>=min) if(max==null || now.addDate(added)<=max) d+='<span class="quickDateItem" value="'+now.addDate(added)+'" onclick="quickdate(new Date($(this).attr(\'value\')));" >' + ShortDay[now.addDate(added).getDay()] + ' ' + now.addDate(added).getFormatedString() + ' </span><br>';
	added = 21; if(now.addDate(added)>=min) if(max==null || now.addDate(added)<=max) d+='<span class="quickDateItem" value="'+now.addDate(added)+'" onclick="quickdate(new Date($(this).attr(\'value\')));" >' + ShortDay[now.addDate(added).getDay()] + ' ' + now.addDate(added).getFormatedString() + ' </span><br>';
	
	$(".QuickDate").html(d);
}
function close_table(val){
	var showtime = $("[name=textfield2].timepicker9").is(":visible");
   	$('.pageheader').css("display","none");
	$('.pageheader').get(0).change.select();
	var callback = $('.pageheader').get(0).callback;
	var isChanged = $('.pageheader').get(0).changed;
	if(isChanged == null) isChanged = false;
	$('.pageheader').get(0).changed = false;
	if(val == null) val = $('.pageheader').get(0).change.val();
	if(showtime){
		if(val=="") val = $("[name=textfield]").val();
		val += "&nbsp; &nbsp;" + $("[name=textfield2].timepicker9").val();}
		
	if(callback != null) { callback(val,$('.pageheader').get(0).change,isChanged) };
}
function quickdate(date){ $('.pageheader').get(0).changed = true; $('.pageheader').get(0).change.val(date.getFormatedString());close_table(date.getFormatedString()); }
</script>

<div class="pageheader" style="display:none; position:absolute;">
  <table width="470" border="0" style="background:white;">
    <tr style=" border-top:#CCC solid 1px;   border-left:#CCC solid 1px; border-right:#CCC solid 1px;">
      <td width="74" style="text-align:center;">Due Date </td>
      <td width="152"><label><input type="text" name="textfield" class="datepickerShow" /></label></td>
      <td width="222"><label><input type="text" name="textfield2" class="timepicker9" onchange="if($('.pageheader').get(0).time==null || $('.pageheader').get(0).time != this.value){$('.pageheader').get(0).changed = true; $('.pageheader').get(0).time = this.value}" /></label></td>
      <td><button onclick="close_table()" class="button_close"><img src="/images/components/task/x.jpg" alt="" width="30px;" height="30px;"></button></td>
    </tr>
    <tr style=" border-bottom:#CCC solid 1px;  border-left:#CCC solid 1px; border-right:#CCC solid 1px;  border-top:#CCC solid 1px; vertical-align:top;">
      <td colspan="2"><div class="datepicker"></div></td>
      <td colspan="2"><table>
          <tr><td><h1>Quick Date</h1></td></tr>
          <tr><td><div style="margin-top:0px;"><span class="QuickDate" ></span></div></td></tr>
          <tr><td>&nbsp;</td></tr>
      </table></td>
    </tr>
  </table>
</div>